'''
Created on Mar 11, 2015

@author: dewey
'''

from pystrat.datamodel import DataObject

class PyStratProject(DataObject):
    
    def __init__(self, _id=None, metadata=None, location_list=None):
        super(PyStratProject, self).__init__(_id, metadata)
        self.locations = {}
        if location_list:
            for location in location_list:
                self.add_location(location)
    
    def add_location(self, location):
        self.locations[location._id] = location
    
    def age_depth_model(self, location_id):
        if location_id in self.locations:
            return self.locations[location_id].age_depth_model
        else:
            return None
    
    def __repr__(self):
        return "PyStratProject(metadata=%s, location_list=%s)" % (repr(self._metadata), repr(list(self.locations.values())))

METADATA_LOCATION_ID = "location_id"
VDATA_ID_AGEDEPTH = "pystrat_age_depth_model"


class DataLocation(DataObject):
    
    def __init__(self, _id=None, metadata=None, data_list=None, xy=None, age_depth_model=None):
        super(DataLocation, self).__init__(_id, metadata)
        self.xy = xy
        self.age_depth_model = age_depth_model
        self.vdata = {}
        if data_list:
            for data in data_list:
                self.add_vdata(data)
            
    def add_vdata(self, vertical_data):
        vertical_data.set_metadata(METADATA_LOCATION_ID, self._id)
        self.vdata[vertical_data._id] = vertical_data
    
    def __repr__(self):
        return "DataLocation(%s, %s, %s, %s, %s)" % (repr(self._id), repr(self._metadata), 
                                                 repr(list(self.vdata.values())), repr(self.xy), repr(self.age_depth_model))

